#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

#route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.2.100
#route add -net 192.168.69.0 netmask 255.255.255.0 gw 192.168.3.69
#fprobe -i eth5 192.168.169.47:5555

evdodev="/dev/sr0"

####
if mount $evdodev -t iso9660 /mnt
then
	echo "Found Novatel CDROM"
	sleep 3
	umount $evdodev
	eject $evdodev
fi

if [ -c /dev/ttyUSB0 ]
then
    echo "Found USB Device"
    echo "Enabling forwarding"
    echo "1" > /proc/sys/net/ipv4/ip_forward

    echo "Setting iptables rules"
    iptables -v -A POSTROUTING -t nat -o ppp0 -j MASQUERADE
    sleep 10
    nohup wvdial &
else
    echo "Unable to get USB device, rebooting"
    sync
    sync
    #reboot
fi
